package com.jvm.interpreter.instruction;

import com.jvm.classfile.model.CpInfo;
import com.jvm.interpreter.Frame;
import com.jvm.interpreter.Instruction;

/**
 * @program: diy_simple_jvm
 * @description: goto指令
 * @author: CaoYong
 * @create: 2021-07-08 13:42
 **/
public class GotoInst implements Instruction {

    public final int offset;

    public GotoInst(int offset) {
        this.offset = offset;
    }

    @Override
    public int offset() {
        return 3;
    }

    @Override
    public void eval(Frame frame) {
        frame.pc += offset;
    }

    static GotoInst parse(java.io.DataInputStream dis, CpInfo[] cp) throws java.io.IOException {
        return new GotoInst(dis.readShort());
    }
}
